package com.taritari.journal.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.taritari.journal.entity.po.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * @author taritari
 * @date 2024-01-24 15:09
 * @description 评论表
 */
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {
    /**
     * 用户是否喜欢该评论
     * */
    @Select("SELECT COUNT(*) FROM `userlike` WHERE user_id = #{userId} and comment_id = #{commentId}")
    int queryCommentIsLike(int userId,int commentId);
    /**
     * 添加用户喜欢
     * */
    @Insert("INSERT INTO userlike VALUES(#{userId},0,#{commentId});")
    int insertCommentLike(int userId,int commentId);
    /**
     * 删除用户喜欢表s
     * */
    @Delete("DELETE FROM userlike WHERE user_id = #{userId} AND comment_id = #{commentId}")
    int deleteCommentLike(int userId,int commentId);
    /**
     * 改变评论的like字段
     * */
    int commentLikesChanges(int number,int commentId);
    /**
     * 添加评论
     * */
    int insertComment(int treeHoldId,String content,int authorId,String replyId);
    /**
     * 通过树洞id查询评论总条数
     * */
    int queryCountByTreeHoldId(int treeHoldId);
    /**
     * 检测是否已经评论
     * */
    @Select("SELECT count(*) FROM `comment` WHERE treehole_id = #{treeHoldId} AND author_id = #{authorId}")
    int isComment(int treeHoldId,int authorId);
}
